"""
目录漫游

"""
# import os


# def l_file(root_f):
#     for data in os.listdir(root_f):
#         data_path = os.path.join(root_f, data)
#         # if os.path.isdir(data_path):
#         #     print(f"子目录{data_path}")
#         #     l_file(data_path)
#         #
#         # else:
#         #     print(f"文件{data_path}")
#         if os.path.isfile(data_path):
#             print(f"文件{data_path}")
#         else:
#             print(f"子目录{data_path}")
#             l_file(data_path)
#
#
# root_f = "../天天向上"
#
# l_file(root_f)


import json
from datetime import datetime

l = [{
    "name": "zs张三",
    "age": 12,
    "height": 180.0,
    "money": True,
    "car": None,
    "hot": ('lq篮球',),
    "data": datetime.today(),
    "set": {1, 2, 3}
}]


class MyGet(json.JSONEncoder):
    def default(self, o):
        print(o, type(o))
        if isinstance(o, set):
            return list(o)
        elif isinstance(o, datetime):
            return o.strftime("%Y%m%d %H%M%S")
        return "I'm fine"


str_l = json.dumps(l, cls=MyGet)
print(str_l)
# print(type(str_l))

str = '[{"name": "zs\u5f20\u4e09", "date": "20240625 155527", "set": [1, 2, 3]}]'


class MyNew(json.JSONDecoder):
    def decode(self, s,):
        datas = json.loads(str)
        for data in datas:
            if "date" in data:
                data["date"] = datetime.strptime(data["date"], "%Y%m%d %H%M%S")
            if "set" in datas:
                data["set"] = set(data["set"])
        return datas


new_l = json.loads(str, cls=MyNew)
print(new_l)
print(type(new_l))
for data in new_l:
    print(data)

# import json
# import pickle
#
#
# # 定义一个类
# class Person:
#     def __init__(self, name, age):
#         self.name = name
#         self.age = age
#
#     def greet(self):
#         return f"Hello,my name is {self.name} and I am {self.age} years old."
#
#
# # 创建一个 Person 对象
# john = Person("John", 30)
#
# # 使用pickle 序列化对象
# with open("john.pickle", "wb") as f:
#     pickle.dump(john, f)
#
# # 反序列化对象
# with open("john.pickle", "rb") as f:
#     john_from_pickle = pickle.load(f)
#
# # 测试反序列化后的对象
# print(john_from_pickle.greet())
